import { API_BASE_URL } from '@/utils/url'
import { getToken } from '@/utils/token'
import dayjs from 'dayjs'

export const articleColumn = [
    {
        label: '标题',
        prop: 'title',
        search: true,
        rules: [
            {
                required: true,
                message: '此项必填',
                trigger: 'blur',
            },
        ],
        span: 17,
        row: true,
    },
    {
        label: '内容',
        prop: 'content',
        type: 'textarea',
        span: 24,
        formatter: () => '...',
    },
    {
        label: '发布时间',
        prop: 'publishTime',
        type: 'datetime',
        formatter: (_row, val) => {
            return val ? dayjs(val).format('YYYY-MM-DD HH:mm:ss') : ''
        },
        row: true,
    },
    {
        label: '作者',
        prop: 'userId',
        display: true,
        row: true,
    },
    {
        label: '封面',
        prop: 'poster',
        type: 'upload',
        listType: 'picture-img',
        width: 100,
        propsHttp: {
            res: 'data[0]',
        },
        headers: {
            Authorization: `Bearer ${getToken()}`,
        },
        action: `${API_BASE_URL}/upload`,
        data: {
            folder: 'article',
        },
        row: true,
    },

    {
        label: '是否开启评论',
        prop: 'comment',
        type: 'switch',
        dicData: [
            { label: '关闭', value: 0 },
            { label: '开启', value: 1 },
        ],
        value: 0,
        row: true,
    },

]
